﻿using AutoMapper;
using MediatR;
using T.S.BaseData.Api.AppClinet.Commend.Cultivationinfo;
using T.S.BaseData.Api.Dto.Cultivationinfo;
using T.S.BaseData.Domain.Entity;
using T.S.BaseData.ErrorCode;
using T.S.BaseData.Infrastructure.Base;

namespace T.S.BaseData.Api.AppClinet.CommendHand.Cultivationinfo
{
    public class EnterpriseinfoGetCommandHandle : IRequestHandler<EnterpriseinfoGetCommand, ApiResult<List<GetEnterpriseinfoDto>>>
    {
        private readonly IBaseRepository<EnterpriseInfo> enterRepo;
        private readonly IMapper mapper;

        public EnterpriseinfoGetCommandHandle(IBaseRepository<EnterpriseInfo> enterRepo, 
            IMapper mapper)
        {
            this.enterRepo = enterRepo;
            this.mapper = mapper;
        }

        public Task<ApiResult<List<GetEnterpriseinfoDto>>> Handle(EnterpriseinfoGetCommand request, CancellationToken cancellationToken)
        {

            ApiResult<List<GetEnterpriseinfoDto>> result = new ApiResult<List<GetEnterpriseinfoDto>>();

            var ent = enterRepo.GetAll().Where(x=>x.GoodsId == request.GoodsId);

            result.Code = ApiEnums.Success;
            result.Data = mapper.Map<List<GetEnterpriseinfoDto>>(ent);
            result.Meg = "显示成功";

            return Task.FromResult(result);
        }
    }
}
